package cc.javaee.bbs.service.activity;

import cc.javaee.bbs.dao.activity.*;
import cc.javaee.bbs.model.activity.KbrActivityDynamic;
import cc.javaee.bbs.params.BizOutMap;
import cc.javaee.bbs.params.DbResultMap;
import cc.javaee.bbs.params.WebParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ActivityDynamicService{
	@Autowired
	ActivityDao activityDao;
	
	@Autowired
	ActivityPrizeDao activityPrizeDao;
	@Autowired
	ActivityArrangeDao activityArrangeDao;
	@Autowired
	ActivityFileDao activityFileDao;
	
	@Autowired
	ActivityCustomerDao activityCustomerDao;
	@Autowired
	PrizeCustomerDao prizeCustomerDao;
	
	@Autowired
	CircleDao circleDao;
	@Autowired
	DynamicCommentDao dynamicCommentDao;
	@Autowired
	DynamicLaudDao dynamicLaudDao;
	@Autowired
	ActivityDynamicDao activityDynamicDao;
	
	public void saveDynamic(WebParams params) {
		WebParams par=new WebParams();
		Integer actId=params.getInteger("actId");
		Integer dynaName=params.getInteger("dynaName");
		String context=params.getString("context");
		String path=params.getString("path");
		Integer custId=params.getInteger("custId");
		par.put("id",actId);
		DbResultMap act= activityDao.findDb(par);
		KbrActivityDynamic dynamic=new KbrActivityDynamic();
		dynamic.setActId(actId);
		dynamic.setCustId(custId);
		dynamic.setContext(context);
		dynamic.setFilePath(path);
		dynamic.setCreateTime(new Date());
		activityDynamicDao.insert(dynamic);
	}
	public BizOutMap dynamicList(WebParams params) {
		BizOutMap out=new BizOutMap();
		Integer actId=params.getInteger("actId");
		Integer circleId=params.getInteger("circleId");
             params.clear();		
             params.put("circleId", circleId);
		List<DbResultMap> dynamicList=activityDynamicDao.findDbList(params);
		if(dynamicList!=null&&dynamicList.size()>0){
			for (DbResultMap db : dynamicList) {
				Integer dynamicId=db.getId();
				params.clear();
				params.put("dynamicId", dynamicId);
				Integer  laudCount=dynamicLaudDao.findLaudCount(params);
				db.put("laudCount", laudCount);
				
				List<DbResultMap> commonList=new ArrayList<DbResultMap>();
				params.clear();
				params.put("dynamicId", dynamicId);
				commonList=dynamicCommentDao.findDbList(params);
				db.put("commonCount", commonList.size());
			}
		}
		out.put("dynamicList", dynamicList);
		return out;
	}
	
	
}
